package com.cao.meet.vocie;

import android.content.Context;
import android.media.AudioManager;

/**
 * Created by ZKTH
 * Time ： 2018/12/24.16:09
 * data ： 调节音量大小
 */

public class AdjustmentVoiceUtil {

    private static AdjustmentVoiceUtil voiceUtil;
    private Context context;
    private AudioManager mAudioManager;

    private AdjustmentVoiceUtil() {
    }

    public static AdjustmentVoiceUtil getVoiceUtil() {
        if (voiceUtil == null) {
            getVoiceUtils();
        }
        return voiceUtil;
    }

    private static synchronized void getVoiceUtils() {
        if (voiceUtil == null) {
            voiceUtil = new AdjustmentVoiceUtil();
        }
    }

    public AdjustmentVoiceUtil init(Context context) {
        this.context = context;
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        return voiceUtil;
    }

    /**
     * 设置声音的方法
     * @param voice_type 设置声音的类型
     * @param voice_value 要将媒体音量调节至什么程度
     */
    public void change_voice(int voice_type, int voice_value) {
        if (voice_value < 0 || voice_value > 100)
            throw new IllegalArgumentException("voice_value must be > 0 < 100");
        mAudioManager.setStreamVolume(voice_type, voice_value, AudioManager.FLAG_SHOW_UI);
    }

    /**
     * 获取当前音量
     * @param voice_type 获取音量的类型
     * @return 返回当前音量类型值
     */
    public int get_voice(int voice_type){
        int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        return volume;
    }

}
